﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    
</head>
<body>
<form class="layui-form"  id="form" action="${ctx}/person/savePassword"  >
    <div class="layui-form-item layui-col-md5" style="margin-top: 50px">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-block">
            <input type="password"   id="oldPassword" placeholder="请输入原密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password"  id="newPassword" placeholder="请输入6-20位新密码"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">确认新密码</label>
        <div class="layui-input-block">
            <input type="password" id="newPassword1" placeholder="请确认新密码"  autocomplete="off" class="layui-input">
        </div>
    </div>
 
    <c:if test="${empty detail}">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="button" id="formBtn"  >立即提交</button>
            </div>
        </div>
    </c:if>
</form>
<script>

 //Demo
layui.use('form', function(){
	 var $ = layui.$;
    var  form = layui.form;
    //监听提交
 

    document.getElementById("formBtn").addEventListener("click",function(){
    	   var oldPassword=document.getElementById("oldPassword").value;
    	   var newPassword=document.getElementById("newPassword").value;
    	   var newPassword1=document.getElementById("newPassword1").value;
    	   if(oldPassword==""){
    		   layer.alert("请输入原密码");
    	   }else if(newPassword==""||newPassword.length<6||newPassword.length>20){
    		   layer.alert("请输入6-20位新密码");
    	   }else  if(newPassword1==""){
    		   layer.alert("请输入新密码");
    	   }else if(newPassword!=newPassword1){
    		   layer.alert("请验证新密码");
    	   }else{
    		   $.post("${ctx}/person/savePassword",{"oldPassword":oldPassword,"newPassword":newPassword},function(msg){
    			  if(msg==0){
    				  layer.confirm('密码修改成功！', {
    					  btn: ['确定'] //按钮
    					}, function(){
    						// 使用top.location.href确保跳出iframe，直接跳转到登录页面
    						top.location.href='${ctx}/logout';
    					});
    			  }else{
    				  layer.alert("原密码错误！")
    			  }
    		   })
    		   
    
    		   
    		   
    		   
    		   
    		   
    	   }
    	   /* if(open==false){
    		   window.location.href="${ctx}/label/saveLabel?id="+id+"&open="+open+"&content="+content+"&grantQuantity="+grantQuantity;
    	   }else if(grantQuantity==""){
    		  // layer.alert("请输入发放数量", {icon: 2});
    		   alert("请输入发放数量");
    	   }else if(!num.test(grantQuantity)){
    		   alert("请输入正整数")
    	   }else{
    		   window.location.href="${ctx}/label/saveLabel?id="+id+"&open="+open+"&content="+content+"&grantQuantity="+grantQuantity;
    	   } */
    	 })

}); 
 




</script>
</body>
</html>



